﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BUS;
using DTO;
using System.Drawing;

namespace TuyenDungViecLam.NhaTuyenDung
{
    public partial class CapNhatNhaTuyenDung : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DrlTinhThanh.DataSource = ChiTietCongViec_BUS.DanhSachNoiLamViec();
                DrlTinhThanh.DataTextField = "Ten";
                DrlTinhThanh.DataValueField = "MaTinhThanh";
                DrlTinhThanh.DataBind();

                int userID = int.Parse(Session["UserID"].ToString());
                //int userID = 12;

                NhaTuyenDung_DTO nhaTuyenDung = NhaTuyenDung_BUS.LayDanhSachThongTinNhaTuyenDungTheoUserID(userID);

                //showw len giao dien
                txtUsername.Text = nhaTuyenDung.UserName;
                txtTen.Text = nhaTuyenDung.Ten;
                txtEmail.Text = nhaTuyenDung.Email;
                TxtNguoiLienHe.Text = nhaTuyenDung.NguoiLienHe;
                txtdienthoai.Text = nhaTuyenDung.DienThoai;
                txtdidong.Text = nhaTuyenDung.Didong;
                txtDiachi.Text = nhaTuyenDung.DiaChi;
                Txtfax.Text = nhaTuyenDung.Fax;
                TxtSoTaiKhoan.Text = nhaTuyenDung.SoTaiKhoan;
                DrlTinhThanh.SelectedValue = nhaTuyenDung.MaTinhThanh.ToString();
                TxtGioiThieu.Text = nhaTuyenDung.GioiThieu;
                TxtQuymo.Text = nhaTuyenDung.QuyMo;
                

            }
        }

        protected void BtDangKy_Click(object sender, EventArgs e)
        {
            try
            {
                int userID = int.Parse(Session["UserID"].ToString());
                //int userID = 12;


                NhaTuyenDung_DTO nhaTuyenDung = new NhaTuyenDung_DTO();

                nhaTuyenDung.UserName = txtUsername.Text;
                nhaTuyenDung.Date = DateTime.Now.Date;
                nhaTuyenDung.Ten = txtTen.Text;
                nhaTuyenDung.GioiThieu = TxtGioiThieu.Text;
                nhaTuyenDung.QuyMo = TxtQuymo.Text;
                nhaTuyenDung.NguoiLienHe = TxtNguoiLienHe.Text;
                nhaTuyenDung.Fax = Txtfax.Text;
                nhaTuyenDung.SoTaiKhoan = TxtSoTaiKhoan.Text;
                nhaTuyenDung.Email = txtEmail.Text;
                nhaTuyenDung.DienThoai = txtdienthoai.Text;
                nhaTuyenDung.Didong = txtdidong.Text;
                nhaTuyenDung.NgayDangKy = DateTime.Now.Date;
                nhaTuyenDung.DiaChi = txtDiachi.Text;
                nhaTuyenDung.MaTinhThanh = int.Parse(DrlTinhThanh.SelectedItem.Value.ToString());
                
                bool kq = NhaTuyenDung_BUS.CapNhatThongTinNhaTuyenDung(userID,nhaTuyenDung);

                if (kq == true)
                {
                    divCapnhat.Visible = false;
                    divThongbao.Visible = true;
                    lbThongbao.Text = "cập nhật thành công";
                    lbThongbao.ForeColor = Color.Blue;
                }
                else
                {
                    
                    divThongbao.Visible = true;
                    lbThongbao.Text = "cập nhật thất bại";
                    lbThongbao.ForeColor = Color.Red;
                }
               
            }
            catch (Exception)
            {
                divThongbao.Visible = true;
                lbThongbao.Text = "Cập nhật thất bại";
                lbThongbao.ForeColor = Color.Red;
            }
        }
    }
}
